# -*- coding: utf-8 -*-
"""
Created on 2024-06-13 16:31:27
---------
@summary: 爬虫入口
---------
@author: Administrator
"""
from datetime import datetime

from flask import Flask
from flask import jsonify
from flask import request
import json

from encoders.DateTImeDecoder import DateTimeEncoder
from spiders.appsflyer import Appsflyer

app = Flask(__name__)

@app.route('/appsflyer_data', methods=['POST'])
def appsflyer_data():
    # 直接调用feapder
    data_json = request.get_data()
    datas = json.loads(data_json)

    i = 0
    for data in datas:
        media_source = data['mediaSource']
        email = data['email']
        password = data['password']
        app_id_geos = data['appIdGeos']
        day = data['day']
        now = data['now']
        batch_id = data["batchId"]

        for item in app_id_geos:
            campaign = item['campaign']
            geo = item['geo']
            app_id = item["appId"]

            appsflyer_data_item = {
                "media_source": media_source,
                "email": email,
                "password": password,
                "campaign": campaign,
                "geo": geo,
                "app_id": app_id,
                "day": day,
                "now": now,
                "batch_id": batch_id
            }
            i += 1
            Appsflyer(appsflyer_data_item).start()
    print(f"共{i}个任务")
    return "success"

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=9999)

